package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.danmo.domain.DanmoMountWorks;
import com.muyu.danmo.service.IDanmoMountWorksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 装裱作品Controller
 *
 * @author ruoyi
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/mountWorks")
public class DanmoMountWorksController extends BaseController
{
    @Autowired
    private IDanmoMountWorksService danmoMountWorksService;

    /**
     * 查询装裱作品列表
     */
//    @RequiresPermissions("system:mountWorks:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoMountWorks>> list(DanmoMountWorks danmoMountWorks)
    {
        startPage();
        List<DanmoMountWorks> list = danmoMountWorksService.selectDanmoMountWorksList(danmoMountWorks);
        return getDataTable(list);
    }

    /**
     * 导出装裱作品列表
     */
//    @RequiresPermissions("system:mountWorks:export")
    @Log(title = "装裱作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoMountWorks danmoMountWorks)
    {
        List<DanmoMountWorks> list = danmoMountWorksService.selectDanmoMountWorksList(danmoMountWorks);
        ExcelUtil<DanmoMountWorks> util = new ExcelUtil<DanmoMountWorks>(DanmoMountWorks.class);
        util.exportExcel(response, list, "装裱作品数据");
    }

    /**
     * 获取装裱作品详细信息
     */
//    @RequiresPermissions("system:mountWorks:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoMountWorksService.selectDanmoMountWorksById(id));
    }

    /**
     * 新增装裱作品
     */
//    @RequiresPermissions("system:mountWorks:add")
    @Log(title = "装裱作品", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoMountWorks danmoMountWorks)
    {
        return toAjax(danmoMountWorksService.insertDanmoMountWorks(danmoMountWorks));
    }

    /**
     * 修改装裱作品
     */
//    @RequiresPermissions("system:mountWorks:edit")
    @Log(title = "装裱作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoMountWorks danmoMountWorks)
    {
        return toAjax(danmoMountWorksService.updateDanmoMountWorks(danmoMountWorks));
    }

    /**
     * 删除装裱作品
     */
//    @RequiresPermissions("system:mountWorks:remove")
    @Log(title = "装裱作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoMountWorksService.deleteDanmoMountWorksByIds(ids));
    }
}
